package com.example.demo.service.observe;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class UserService implements ApplicationEventPublisherAware {
    private ApplicationEventPublisher applicationEventPublisher;
    @Override
    public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
        this.applicationEventPublisher = applicationEventPublisher;
    }

    public void register(String userName) {
        log.info("当前线程为：" + Thread.currentThread().getId());
        //执行注册逻辑
        log.info("[register][执行用户{}]的注册逻辑", userName);
        //发布
        applicationEventPublisher.publishEvent(new UserRegisterEvent(this, userName));
    }
}
